package me.shiqiang.im.conf;

import com.tst.common.oss.OSSConfig;
import org.slf4j.LoggerFactory;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

/**
 * OSS配置
 * Created by John on 2017/10/14.
 */
@Configuration
public class OSSConfiguration implements EnvironmentAware {
    private static final org.slf4j.Logger logger = LoggerFactory.getLogger(OSSConfiguration.class);

    public static final String ENDPOINT = "oss.endpoint";
    public static final String ACCESSKEY_ID = "oss.accessKeyId";
    public static final String ACCESSKEY_SECRET = "oss.accessKeySecret";
    public static final String BUCKET_NAME = "oss.bucketName";

    private Environment environment;

    @Override
    public void setEnvironment(Environment environment) {
        this.environment = environment;
        this.initConfig();
    }


    public void initConfig() {
        OSSConfig.getInstance().setEndpoint(environment.getProperty(ENDPOINT));
        OSSConfig.getInstance().setAccessKeyId(environment.getProperty(ACCESSKEY_ID));
        OSSConfig.getInstance().setAccessKeySecret(environment.getProperty(ACCESSKEY_SECRET));
        OSSConfig.getInstance().setBucketName(environment.getProperty(BUCKET_NAME));

        logger.info("OSS配置为" + OSSConfig.getInstance().toString());
    }
}
